from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-18 14:04:29.549266
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 18, Jan, 2022
Time: 14:04:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7534
Nobs: 540.000 HQIC: -48.1889
Log likelihood: 6280.50 FPE: 8.91955e-22
AIC: -48.4687 Det(Omega_mle): 7.56175e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.372868 0.070711 5.273 0.000
L1.Burgenland 0.102092 0.042739 2.389 0.017
L1.Kärnten -0.113539 0.022100 -5.138 0.000
L1.Niederösterreich 0.188831 0.088960 2.123 0.034
L1.Oberösterreich 0.113529 0.088249 1.286 0.198
L1.Salzburg 0.266722 0.045142 5.909 0.000
L1.Steiermark 0.027697 0.059497 0.466 0.642
L1.Tirol 0.106818 0.047973 2.227 0.026
L1.Vorarlberg -0.077139 0.042423 -1.818 0.069
L1.Wien 0.018407 0.078187 0.235 0.814
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067820 0.154394 0.439 0.660
L1.Burgenland -0.043914 0.093318 -0.471 0.638
L1.Kärnten 0.040504 0.048254 0.839 0.401
L1.Niederösterreich -0.205107 0.194239 -1.056 0.291
L1.Oberösterreich 0.448511 0.192688 2.328 0.020
L1.Salzburg 0.286977 0.098565 2.912 0.004
L1.Steiermark 0.111897 0.129908 0.861 0.389
L1.Tirol 0.307531 0.104746 2.936 0.003
L1.Vorarlberg 0.020611 0.092629 0.223 0.824
L1.Wien -0.025720 0.170717 -0.151 0.880
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197810 0.036123 5.476 0.000
L1.Burgenland 0.091132 0.021833 4.174 0.000
L1.Kärnten -0.007588 0.011290 -0.672 0.501
L1.Niederösterreich 0.234901 0.045445 5.169 0.000
L1.Oberösterreich 0.164286 0.045082 3.644 0.000
L1.Salzburg 0.040353 0.023060 1.750 0.080
L1.Steiermark 0.025493 0.030394 0.839 0.402
L1.Tirol 0.082205 0.024507 3.354 0.001
L1.Vorarlberg 0.054063 0.021672 2.495 0.013
L1.Wien 0.118893 0.039941 2.977 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122415 0.036195 3.382 0.001
L1.Burgenland 0.042395 0.021876 1.938 0.053
L1.Kärnten -0.014079 0.011312 -1.245 0.213
L1.Niederösterreich 0.173179 0.045535 3.803 0.000
L1.Oberösterreich 0.332551 0.045172 7.362 0.000
L1.Salzburg 0.102606 0.023106 4.441 0.000
L1.Steiermark 0.109665 0.030454 3.601 0.000
L1.Tirol 0.091129 0.024556 3.711 0.000
L1.Vorarlberg 0.056943 0.021715 2.622 0.009
L1.Wien -0.017263 0.040021 -0.431 0.666
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.113435 0.068540 1.655 0.098
L1.Burgenland -0.041972 0.041426 -1.013 0.311
L1.Kärnten -0.045412 0.021421 -2.120 0.034
L1.Niederösterreich 0.142359 0.086228 1.651 0.099
L1.Oberösterreich 0.166543 0.085540 1.947 0.052
L1.Salzburg 0.280817 0.043756 6.418 0.000
L1.Steiermark 0.063941 0.057670 1.109 0.268
L1.Tirol 0.154410 0.046500 3.321 0.001
L1.Vorarlberg 0.094293 0.041121 2.293 0.022
L1.Wien 0.075403 0.075786 0.995 0.320
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.093068 0.053303 1.746 0.081
L1.Burgenland 0.019925 0.032217 0.618 0.536
L1.Kärnten 0.052351 0.016659 3.142 0.002
L1.Niederösterreich 0.190803 0.067059 2.845 0.004
L1.Oberösterreich 0.321641 0.066524 4.835 0.000
L1.Salzburg 0.039600 0.034029 1.164 0.245
L1.Steiermark -0.001632 0.044850 -0.036 0.971
L1.Tirol 0.124241 0.036163 3.436 0.001
L1.Vorarlberg 0.063249 0.031979 1.978 0.048
L1.Wien 0.097966 0.058939 1.662 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167644 0.064549 2.597 0.009
L1.Burgenland 0.008472 0.039014 0.217 0.828
L1.Kärnten -0.065389 0.020174 -3.241 0.001
L1.Niederösterreich -0.110886 0.081207 -1.365 0.172
L1.Oberösterreich 0.212555 0.080558 2.639 0.008
L1.Salzburg 0.051917 0.041208 1.260 0.208
L1.Steiermark 0.255238 0.054311 4.700 0.000
L1.Tirol 0.497830 0.043792 11.368 0.000
L1.Vorarlberg 0.064842 0.038726 1.674 0.094
L1.Wien -0.078413 0.071373 -1.099 0.272
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167615 0.071395 2.348 0.019
L1.Burgenland -0.008970 0.043152 -0.208 0.835
L1.Kärnten 0.062607 0.022314 2.806 0.005
L1.Niederösterreich 0.176106 0.089820 1.961 0.050
L1.Oberösterreich -0.068760 0.089103 -0.772 0.440
L1.Salzburg 0.208202 0.045578 4.568 0.000
L1.Steiermark 0.137218 0.060072 2.284 0.022
L1.Tirol 0.055897 0.048437 1.154 0.248
L1.Vorarlberg 0.143281 0.042833 3.345 0.001
L1.Wien 0.129766 0.078943 1.644 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.396747 0.041699 9.515 0.000
L1.Burgenland -0.002949 0.025203 -0.117 0.907
L1.Kärnten -0.020696 0.013032 -1.588 0.112
L1.Niederösterreich 0.202344 0.052460 3.857 0.000
L1.Oberösterreich 0.238103 0.052041 4.575 0.000
L1.Salzburg 0.035198 0.026620 1.322 0.186
L1.Steiermark -0.016434 0.035085 -0.468 0.640
L1.Tirol 0.087062 0.028290 3.077 0.002
L1.Vorarlberg 0.050061 0.025017 2.001 0.045
L1.Wien 0.034136 0.046107 0.740 0.459
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033423 0.099215 0.162067 0.136865 0.086032 0.082758 0.027991 0.209342
Kärnten 0.033423 1.000000 -0.026692 0.133350 0.048163 0.083791 0.446877 -0.070086 0.093323
Niederösterreich 0.099215 -0.026692 1.000000 0.307499 0.124059 0.265181 0.065373 0.157677 0.279596
Oberösterreich 0.162067 0.133350 0.307499 1.000000 0.217022 0.292245 0.169460 0.133460 0.231619
Salzburg 0.136865 0.048163 0.124059 0.217022 1.000000 0.128043 0.086068 0.107967 0.126910
Steiermark 0.086032 0.083791 0.265181 0.292245 0.128043 1.000000 0.137998 0.104239 0.027991
Tirol 0.082758 0.446877 0.065373 0.169460 0.086068 0.137998 1.000000 0.065167 0.149376
Vorarlberg 0.027991 -0.070086 0.157677 0.133460 0.107967 0.104239 0.065167 1.000000 -0.006056
Wien 0.209342 0.093323 0.279596 0.231619 0.126910 0.027991 0.149376 -0.006056 1.000000